package cs340.stormtroopers.hypeerweb;

/**
 * Concrete subclass of SendVisitor used for testing purposes. 
 * 
 * @author William Highland
 */
public class ConcreteSendVisitor extends SendVisitor
{
	/**
	 * The key used in a key-value pair of the parameters to identify the message to send to the target Node. 
	 */
	protected static String MESSAGE_KEY = "message";
	
	@Override
	public void visit(Node node, Parameters parameters)
	{
		if(!parameters.containsKey(MESSAGE_KEY))
		{
			System.err.println("You must specify a message in the parameters object" +
					"before trying to send. \n   Otherwise I don't know what I'm sending. \n" +
					"The mapping should look like " + MESSAGE_KEY + ":THE_MESSAGE. Where THE_MESSAGE " +
					"is any Java Object");
			return;
		}
		super.visit(node, parameters);
	}
	
	@Override
	protected void targetOperation(Node node, Parameters parameters)
	{
		Contents contents = node.getContents();
		contents.put(MESSAGE_KEY, parameters.get(MESSAGE_KEY));
	}

	@Override
	protected void intermediateOperation(Node node, Parameters parameters)
	{
		// Does nothing in this instance
	}

}
